package com.platform.controller;

import java.util.List;
import java.util.Map;

import com.platform.entity.UserVo;
import com.platform.service.AmountBillService;
import com.platform.service.ApiUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.platform.entity.AmountBillEntity;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;

/**
 * 账单流水Controller
 *
 * @author zhurusen
 * @email 524227263@qq.com
 * @date 2018-06-03 15:04:03
 */
@Controller
@RequestMapping("amountbill")
public class AmountBillController {
    @Autowired
    private AmountBillService apiAmountBillService;
    @Autowired
    private ApiUserService apiUserService;


    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("apiamountbill:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<AmountBillEntity> apiAmountBillList = apiAmountBillService.queryList(query);

        for (AmountBillEntity info : apiAmountBillList) {
            UserVo userVo = apiUserService.queryObject(info.getUserId());
            info.setUserName(userVo != null ? userVo.getNickname() : "");
        }


        int total = apiAmountBillService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(apiAmountBillList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("apiamountbill:info")
    @ResponseBody
    public R info(@PathVariable("id") Long id) {
        AmountBillEntity apiAmountBill = apiAmountBillService.queryObject(id);

        return R.ok().put("apiAmountBill", apiAmountBill);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("apiamountbill:save")
    @ResponseBody
    public R save(@RequestBody AmountBillEntity apiAmountBill) {
        apiAmountBillService.save(apiAmountBill);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("apiamountbill:update")
    @ResponseBody
    public R update(@RequestBody AmountBillEntity apiAmountBill) {
        apiAmountBillService.update(apiAmountBill);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("apiamountbill:delete")
    @ResponseBody
    public R delete(@RequestBody Long[] ids) {
        apiAmountBillService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<AmountBillEntity> list = apiAmountBillService.queryList(params);

        return R.ok().put("list", list);
    }
}
